import random
from datetime import datetime, timedelta


def generate_insert_sql(count=100):
    base_time = datetime.now()
    sqls = []

    for i in range(1, count + 1):
        # 生成时间数据
        time_offset = timedelta(minutes=i)
        update_time = (base_time - time_offset).strftime('%Y-%m-%d %H:%M:%S')
        create_time = (base_time - time_offset - timedelta(seconds=30)).strftime('%Y-%m-%d %H:%M:%S')
        client_time = (base_time - time_offset - timedelta(seconds=15)).strftime('%Y-%m-%d %H:%M:%S')
        # 生成随机数据
        coord_x = round(116.3 + random.random(), 6)
        coord_y = round(39.9 + random.random(), 6)


        sql = f"""INSERT INTO trace.tr_log_patrol_pos (update_time,create_time,client_time,coordinate_x, coordinate_y, patrol_id, card_id,imei, in_grid_flag,
road_id, accuracy) VALUES (
            '{update_time}', 
            '{create_time}', 
            '{client_time}', 
            {coord_x},
            {coord_y},
            {11120203},
            'CARD_{random.randint(10000, 99999)}', 
            'imeitest',
            1,
            '道路_{random.randint(1, 20)}',
            {random.randint(0, 1)}
            );"""
        sqls.append(sql)

    return sqls


# 生成100条SQL
insert_sqls = generate_insert_sql(100)

# 打印前5条示例
for sql in insert_sqls[:5]:
    print(sql)
